package com.mapper;

import com.dto.FriendsCommentDto;
import com.pojo.Friends;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface FriendsMapper {
    /**
     * 发朋友圈
     * @param friends
     */
    @Insert("insert into notes (friend_id,phone,notes,image,create_time) value (#{friendId},#{phone},#{notes},#{image},#{createTime})")
    void save(Friends friends);

    /**
     * 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @Select("select friend_id friendId,phone,notes,image,count,create_time createTime from notes limit #{page},#{pageSize}")
    List<Friends> pageQuery(int page, int pageSize);

    /**
     * 查询总数量
     * @return
     */
    @Select("select count(*) from notes")
    int getTotal();

    /**
     * 点赞
     * @param friendId
     */
    @Update("update notes set count = count+1 where friend_id=#{friendId}")
    void addcount(Long friendId);

    /**
     * 写评论
     * @param friendsCommentDto
     */
    @Insert("insert into comment (friend_id,phone,notes,create_time) value (#{friendId},#{phone},#{notes},#{createTime})")
    void savecomment(FriendsCommentDto friendsCommentDto);

    @Select("select friend_id friendId,phone,notes,create_time createTime from comment where friend_id=#{friendId}")
    List<FriendsCommentDto> selectcomment(Long friendId);

    @Select("select name from user where phone=#{phone}")
    String selectNameByPhone(String phone);

}
